<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title></title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/static/css/css.css">
</head>
<body>

	<form:form id="form" method="post" commandName="organization">
		<form:hidden path="organization_id" />
		<form:hidden path="parent_id" />
		<form:hidden path="parent_path" />
		
		<div class="form-group">
			<form:label path="organization_name">名称：</form:label>
			<form:input path="organization_name" />
		</div>
		<shiro:hasPermission name="organization:update">
			<form:button id="updateBtn">修改</form:button>
		</shiro:hasPermission>

		<shiro:hasPermission name="organization:delete">
			<c:if test="${organization.parent_id != 0}">
				<form:button id="deleteBtn">删除</form:button>
			</c:if>
		</shiro:hasPermission>

		<shiro:hasPermission name="organization:create">
			<form:button id="appendChildBtn">添加子节点</form:button>
		</shiro:hasPermission>

		<shiro:hasPermission name="organization:update">
			<c:if test="${organization.parent_id ne '0'}">
				<form:button id="moveBtn">移动节点</form:button>
			</c:if>
		</shiro:hasPermission>
	</form:form>

	<script
		src="${pageContext.request.contextPath}/static/js/common/jquery-1.11.0.min.js"></script>
	<script>
		$(function() {
			$("#updateBtn")
					.click(
							function() {
								$("#form")
										.attr("action",
												"${pageContext.request.contextPath}/organization/${organization.organization_id}/update")
										.submit();
								return false;
							});
			$("#deleteBtn")
					.click(
							function() {
								if (confirm("确认删除吗？")) {
									$("#form")
											.attr("action",
													"${pageContext.request.contextPath}/organization/${organization.organization_id}/delete")
											.submit();
								}
								return false;
							});

			$("#appendChildBtn")
					.click(
							function() {
								location.href = "${pageContext.request.contextPath}/organization/${organization.organization_id}/appendChild";
								return false;
							});

			$("#moveBtn")
					.click(
							function() {
								location.href = "${pageContext.request.contextPath}/organization/${organization.organization_id}/move";
								return false;
							});
		});
	</script>
</body>
</html>